/**
 * 档案归还----我的归还
 */
import React from "react";
import PropTypes from "prop-types";
import { routerRedux } from "dva/router";
import { connect } from "dva";
import { Row, Col, Button, Table } from "antd";
import { formatDate } from "utils";

class Checking extends React.Component {
  constructor(props) {
    super(props)

    this.state = {

    }

  }
  componentDidMount() {
    const { getList, menus, pagination } = this.props
    const params = {
      operatingState: menus,
      page: pagination.current
    }
    getList(params)
  }
  render(){
  const { list, pagination,info, showDetails,menus,loading,dispatch } = this.props;  
  const columns = [
    {
      title: "档案年度",
      key: "documentYear",
      dataIndex: "documentYear"
    },
    {
      title: "公证事项",
      key: "notarialMatters",
      dataIndex: "notarialMatters",
      render: (text, record) => {
        const datas = text.split("#")
        const ary = []
        datas.map((item, i) => {
          ary.push(
            <p>{item}</p>
          )
        })
        return ary
      }
    },
    {
      title: "申请人",
      key: "applyName",
      dataIndex: "applyName",
      render: (text, record) => {
        const datas = text.split("#")
        const ary = []
        datas.map((item, i) => {
          ary.push(
            <p>{item}</p>
          )
        })
        return ary
      }
    },
    {
      title: "收件日期",
      key: "createdTime",
      dataIndex: "createdTime",
      render: (record, text) => formatDate(record)
    },
    {
      title: "借阅时间",
      key: "state",
      render: (record, text) => {
        return (
          <div>
            {formatDate(record.borrowStartTime)}
            <span>——</span>
            {formatDate(record.borrowEndTime)}
          </div>
        );
      }
    },
    {
      title: "是否续借",
      key: "renew",
      dataIndex: "renew",
      render: (record, text, index) => {
        return <div>{record == 1 ? "是" : "否"}</div>;
      }
    },
    {
      title: "公证日期",
      key: "notarizationAt",
      dataIndex: "notarizationAt",
      render: (record, text) => formatDate(record)
    },
    {
      title: "归还时间",
      key: "returnTime",
      dataIndex: "returnTime",
      render: (record, text) => formatDate(record)
    },
    {
      title: "归还人",
      key: "returnUserName",
      dataIndex: "returnUserName"
    },
    {
      title: "操作",
      key: "operation",
      render: (record, text) => {
        return <a onClick={() => showDetail(record)}>审核</a>
      }
    }
  ];
  const showDetail = record => {
    dispatch({
      type: "returns/showDetailsinfo",
      payload: record
    });
  };
  const tabProps = {
    loading:loading.effects['returns/query'],
    dataSource: list,
    pagination,
    columns,
    rowKey: record => record.borrowId,
    onChange(page) {
      dispatch({
        type: "returns/query",
        payload: { page: page.current, pageSize: page.pageSize }
      });
    }
  };
  const detailsProps = {
    info,
    showList() {
      dispatch({
        type: "returns/showList",
        payload: {}
      });
    }
  };

  return (
    <div>
        <Table {...tabProps} />
    </div>
  );
};
}
Checking.propTypes = {
  location: PropTypes.object,
  returns: PropTypes.object,
  dispatch: PropTypes.func,
  loading: PropTypes.object
};

export default connect(({ loading, returns }) => ({ loading, returns }))(Checking);
